package org.vaadin.nf4v.core.handler.impl;

import com.vaadin.terminal.SystemError;
import com.vaadin.terminal.Terminal;
import com.vaadin.ui.Window;
import org.vaadin.nf4v.core.NavigableApplication;
import org.vaadin.nf4v.core.NavigationException;
import org.vaadin.nf4v.core.handler.NavigationUncaughtErrorHandler;

import java.io.Serializable;

/**
 * Default NavigationUncaughtErrorHandler implementation.
 * Shows vaadin error alert.
 */
public class DefaultNavigationUncaughtErrorHandler implements NavigationUncaughtErrorHandler {
    @Override
    public void onUncaughtError(Throwable ex) {
        ex.printStackTrace();
        ((Window)NavigableApplication.getCurrentNavigableWindow()).showNotification(
                "Navigation error", ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE
        );
    }
}
